<template>
  <div class="bh-mb-16">
    <Modal v-model="showModal" title="跳转" :width="520" :mask-closable="false">
			<div class="antd-pe-person person-zb" style="position:static">
				<Form ref="formInline" :model="formInline" :rules="ruleInline" inline :label-width="80">
          <FormItem prop="node" label="跳转到">
              <Select v-model="modelData" style="width:400px" placeholder="请选择环节">
                <Option v-for="item in optionList" :value="item.nodeId" :key="item.nodeId">{{ item.nodeName }}</Option>
              </Select>
          </FormItem>
        </Form>
			</div>
			<div slot="footer">
				<Button @click="showModal=false">取消</Button>
				<Button type="primary" :loading="saveLoading" @click="confirm()">确定</Button>
			</div>
		</Modal>
  </div>
</template>

<script>
import pageUtil from '../../lib/bh-vue/utils/pageUtil'
import { request } from 'utils/http'

export default {
  props: {
    queryPath: Object,
    formUrl: String
  },
  data () {
    return {
      showModal: false,
      formInline: {
        node: ""
      },
      ruleInline: {
        node: [
          { required: true, message: '请选择环节', trigger: 'blur' }
        ]
      },
      modelData: "",
      optionList: [],
      taskId: null,
      appName: null,
      saveLoading: false
    }
  },
  computed: {
    // computeDisabled() {

    // }
  },
  methods: {
    initJump (taskId, appName) {
      this.showModal = true
      this.taskId = taskId
      this.appName = appName
      const params = {
        taskId: this.taskId
      }
      const url = window.contextPath + "/sys/emapflow/definition/getAllUserTaskNodes.do"
      request(url, {
        query: params,
        headers:{"Content-Type":"application/x-www-form-urlencoded", "X-Requested-With" : "XMLHttpRequest"}
      }).then(res => {
        this.optionList = res.items
      }).catch(e=>{
        pageUtil.tip(e || "环节获取失败", "danger")
      })
    },
    confirm () {
      this.saveLoading = true
      const params = {
        backTo: this.modelData,
        taskId: this.taskId,
        appName: this.appName,
        commandType: "turnback",
        flowComment: "跳转",
      }
      const url = window.contextPath + "/sys/emapflow/tasks/turnback.do"
      request(url, {
        query: params,
        headers:{"Content-Type":"application/x-www-form-urlencoded", "X-Requested-With" : "XMLHttpRequest"}
      }).then(res => {
        if(res.succeed) {
          pageUtil.tip('跳转成功', 'success')
          this.$emit("save-success")
          this.saveLoading = false;
          this.showModal = false
        }else{
          this.saveLoading = false;
          pageUtil.tip('跳转失败', 'danger')
        }
      })
    }
  },
  components: {
    /* eslint-disable-next-line */
  },
  mounted() {
    // this.queryOrganization();
  },
}
</script>
<style scope>
  .person-zb .antd-pe-center .ivu-radio{
    margin-bottom: 3px;
  }
</style>

